::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::
So, you want your users to update their software?
The subject of automatic updating has been touched on before in an article by John Richardson in Newsletter #112. I have taken it a step or two further with the addition of some features.
The subroutine which I authored (see source code below), when placed in your LB code, will allow you to let users automatically check for and download any new updates to your software. Interested in how it is done? Then read on!
To achieve what I am talking about we make use of a single Windows dll called, “URLmon.dll”. In this dll there is a function called, “URLDownloadToFileA” that will handle all of the file downloading from the Internet.
I will not go into detail on how this function is used because as I mentioned earlier that it was already covered in some detail in newsletter #112 by John Richardson and also by Alyce Watson. [Also, see this API Corner article authored by Alyce Watson in the current issue. --Ed]
First off, there are some things that you have to do with each and every program that you add this functionality to:
Phew! Now that all of that is done I will explain how it all works using the example program that I have enclosed (with comments of course).
When the program asks the user if they want to check for an update and the user answers yes then this is what happens:
When you re-run the program and check for an update again you will notice that it says that it is up-to-date.
Really cool uh!? That is all there is too it.
I have enclosed the demo files in this article but if you would like you can download them from my website at [http://www.noblebell.com] . If you have any comments or suggestions you can voice them at the same website.
--Noble Bell http://www.noblebell.com
' Automatic Update Checking System
' Last Revised: August 3, 2005
' Noble D. Bell
' www.noblebell.com
nomainwin
[setup.main.Window]
'-----Begin code for #main
WindowWidth = 425
WindowHeight = 145
UpperLeftX=int((DisplayWidth-WindowWidth)/2)
UpperLeftY=int((DisplayHeight-WindowHeight)/2)
'-----Begin GUI objects code
statictext #main.statictext1, "Automatic Update Checker", 120, 17, 195, 20
statictext #main.statictext2, "Do you want to check for a later version?", 85, 42, 255, 20
button #main.btnYes,"YES",[btnYesClick], UL, 85, 77, 96, 25
button #main.btnNo,"No",[btnNoClick], UL, 225, 77, 96, 25
'-----End GUI objects code
open "UPDATE" for window_nf as #main
print #main, "font ms_sans_serif 10"
print #main, "trapclose [quit]"
[mainloop]
wait
[quit]
close #main
end
[btnNoClick]
goto [quit]
[btnYesClick]
call CheckInternetForUpdate
goto [mainloop]
' this routine handles all the update checking
Sub CheckInternetForUpdate
open "URLmon" for dll as #url
urlfile$ = "http://www.noblebell.com/proggieupdate.txt" ' the internet location of the download file
localfile$ = "c:\proggieupdate.txt" ' the location on the local machine to store download
' download the file from the website to the local host
calldll #url, "URLDownloadToFileA",_
0 as long,_ 'Leave this setting!
urlfile$ as ptr,_
localfile$ as ptr,_
0 as long,_ 'Must be 0.
0 as long,_ 'Callback address.
ret as long
' if there is any sort of error the dll will return a non-zero value
if ret <> 0 then
notice "There was an error in checking for an update. Aborted!"
close #url
exit sub
end if
' ok, we have the downloaded file. now let's check it against the program's version
' open the downloaded file from the internet and get the version number stored in it
open "c:\proggieupdate.txt" for input as #1
input #1, internetVersion$
close #1
' open the program's file and get the version number stored in it
open "c:\proggie.txt" for input as #1
input #1, currentVersion$
close #1
' compare the two versions and see if the internet version is greater than the current version. if it
' is then we prompt the user to download the later version. Otherwise, well tell the user that they have
' the latest version of the code.
if internetVersion$ > currentVersion$ then
txt$ = ""
txt$ = "There is a newer version available."+chr$(13)
txt$ = txt$ + "Your current version is " + currentVersion$+chr$(13)+chr$(13)
txt$ = txt$ + "The latest version is " + internetVersion$+chr$(13)+chr$(13)
txt$ = txt$ + "Do you want to download the update?"+chr$(13)
confirm txt$;answer$
if answer$ = "no" then exit sub
' download the latest version from the internet and store it on the local drive for processing
urlfile$ = "http://www.noblebell.com/proggie.zip"
localfile$ = "c:\proggie.zip"
calldll #url, "URLDownloadToFileA",_
0 as long,_ 'Leave this setting!
urlfile$ as ptr,_
localfile$ as ptr,_
0 as long,_ 'Must be 0.
0 as long,_ 'Callback address.
ret as long
if ret <> 0 then
notice "There was an error in checking for an update. Aborted!"
close #url
exit sub
end if
notice "Download Complete"+chr$(13)+"Please exit this program and install it."
else
txt$ = "CURRENT"+chr$(13)
txt$ = txt$ + "You have version " + currentVersion$ + " which is"+chr$(13)
txt$ = txt$ + "the latest version."
notice txt$
end if
close #url
kill "c:\proggieupdate.txt"
End Sub
::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::